home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Pascal / MovieScroll / MovieScroll.p next >
Text File  |  1995-01-10  |  5KB  |  157 lines

  1. {• --------------------------------------------------------------- •//}
  2. {• A public domain demo of "movie" type scrolling,    courtesy of        •//}
  3. {• Kenneth A. Long (kenlong@netcom.com).                            •//}
  4. {• An itty bitty bytes™ production, for the benefit of anyone        •//}
  5. {• who can use it.                                                    •//}
  6. {• This is basically just "Bullseye" with some things dumped and    •//}
  7. {• two routines added, and a resource file to back the additions.    •//}
  8.  
  9. {• If you want the text drawn over black, like in the movies,         •//}
  10. {• then some other "girations" are necessary.  This just shows     •//}
  11. {• the scrolling, with style.                                        •//}
  12.  
  13. {• Enjoy!                                                            •//}
  14.  
  15. {• --------------------------------------------------------------- •//}
  16.  
  17. {Revised by Ingemar Ragnemalm:}
  18. {- Took out event handling - the modal dialog is just enough for the demo}
  19. {- Converted to Pascal}
  20. {- Timed the scrolling with TickCount, so it won't get ridiculously slow}
  21. {or, for athat matter, fast.}
  22.  
  23. program MovieScroll;
  24.  
  25. {$IFC UNDEFINED THINK_PASCAL}
  26.     uses
  27.         Types, ToolIntf, Quickdraw, Dialogs, Windows, Menus, OSEvents;
  28. {$ENDC}
  29.  
  30.     var
  31.         textHand: TEHandle;
  32.         appleMenu, fileMenu: MenuHandle;
  33.         shell_window: WindowPtr;
  34.  
  35.     const
  36.         aboutID = 128;
  37.  
  38.         appleID = 1;
  39.         fileID = 2;
  40.         quitItem = 1;
  41.  
  42.     procedure InitMacintosh;
  43.     begin
  44. {$IFC UNDEFINED THINK_PASCAL}
  45.         InitGraf(@qd.thePort);
  46.         InitFonts;
  47.         InitWindows;
  48.         InitMenus;
  49.         TEInit;
  50.         InitDialogs(nil);
  51.         MaxApplZone;
  52. {$ENDC}
  53.         FlushEvents(everyEvent, 0);
  54.         InitCursor;
  55.     end;
  56.  
  57.     procedure OutlineDefault (myDialog: WindowPtr; itemNo: Integer);
  58.         var
  59.             x: Integer;
  60.             rectangle: Rect;
  61.             theHandle: Handle;
  62.     begin
  63.         GetDItem(DialogPtr(myDialog), itemNo, x, theHandle, rectangle);
  64.         PenSize(3, 3);
  65.         InsetRect(rectangle, -4, -4);
  66.         FrameRoundRect(rectangle, 16, 16);
  67.         PenSize(1, 1);
  68.     end;
  69.  
  70.     const
  71.         SCREEN = 2;                    {• Text window useritem.}
  72.         SHOWTIME = 3;
  73.  
  74.         USERITEM = 7;                {• Used to outline default button.}
  75.         textID = 128;                {• rsrc ID# for text used.}
  76.         styleID = 128;                {• rsrc ID# for styl used.}
  77.         kTicksPerStep = 2;            {Number of ticks per step}
  78.     var
  79.         saveWPtr: GrafPtr;            {• Holds previous grafPtr.}
  80.         aboutPtr: DialogPtr;        {• Pointer to dialog.}
  81.         theItem: Integer;            {• Item selected by user.}
  82.         mLoc: Point;                {• Mouse location.}
  83.         rectangle: Rect;
  84.         x: Integer;
  85.         theHandle: Handle;
  86.         txtRect: Rect;                {• Used to hold viewRect.}
  87.         saveTxtHdl: TEHandle;        {• Text handle.}
  88.         finished: Boolean;            {• Pushed 'The End' button yet?}
  89.         styleHdl: StScrpHandle;
  90.         err: OSErr;
  91.  
  92.         thisTime, lastTime: Longint;
  93.  
  94. begin
  95.     InitMacintosh;
  96.  
  97.     GetPort(saveWPtr);                {• Save the old port.}
  98.     saveTxtHdl := textHand;            {• Save the old text hdl.}
  99.  
  100.     {• Get dialog box pointer.}
  101.     aboutPtr := GetNewDialog(aboutID, nil, WindowPtr(-1));
  102.  
  103.     {• This next makes the static text field font monaco 9.}
  104.     SetPort(GrafPtr(aboutPtr));    {• Output to dialog.}
  105.     TextSize(9);                    {• Set text size.}
  106.     TextFont(monaco);                {• Set text font.}
  107.  
  108.     {• Get text window rect.}
  109.     GetDItem(DialogPtr(aboutPtr), SCREEN, x, theHandle, txtRect);
  110.     InsetRect(txtRect, 5, 1);        {• Leave margins for text.}
  111.  
  112.     {• Create styled TERecord.}
  113.     textHand := TEStylNew(txtRect, txtRect);
  114.  
  115.     {• Read the TEXT resource.}
  116.     theHandle := GetResource('TEXT', textID);
  117.     HLock(theHandle);                    {• Lock handle.}
  118.  
  119.     {• Get the style handle.}
  120.     styleHdl := StScrpHandle(Get1Resource('styl', styleID));
  121.     TEStylInsert(theHandle^, SizeResource(theHandle), styleHdl, textHand);    {• move text into text record.}
  122.     TESetJust(1, textHand);
  123.     HUnlock(theHandle);                    {• Unlock handle.}
  124.  
  125.     ShowWindow(aboutPtr);                {• Show dialog box now.}
  126.     TEUpdate(txtRect, textHand);        {• Draw text in viewRect.}
  127.     InsetRect(txtRect, -5, -1);        {• Leave margins for text.}
  128.     FrameRect(txtRect);                {• Draw frame around text.}
  129.     OutlineDefault(aboutPtr, USERITEM);
  130.     GetDItem(DialogPtr(aboutPtr), USERITEM, x, theHandle, rectangle);    {• outline default button.}
  131.     SetDItem(aboutPtr, USERITEM, x, Handle(@OutlineDefault), rectangle);    {• redraw if erased*/}
  132.  
  133.     finished := false;                {• Reset flag.}
  134.     repeat                             {• Repeat until finished.}
  135.         ModalDialog(nil, theItem);    {• Show dialog/get result.}
  136.         case theItem of             {• Control hit.}
  137.             OK: 
  138.                 finished := true;    {• "The End" button hit / close.}
  139.             SHOWTIME: 
  140.                 begin
  141.                     thisTime := TickCount div kTicksPerStep;
  142.                     repeat
  143.                         lastTime := TickCount div kTicksPerStep;
  144.                     {• scroll up a pixel}
  145.                         TEScroll(0, thisTime - TickCount div kTicksPerStep, textHand);
  146.                         thisTime := lastTime;
  147.                     until Button;
  148.                 end;
  149.             otherwise
  150.         end;                            {• End of  case.}
  151.     until finished;            {• End of  mainloop.}
  152.  
  153.     TEDispose(textHand);            {• Reclaim heap space.}
  154.     textHand := saveTxtHdl;            {• Restore global textHand.}
  155.     DisposDialog(aboutPtr);            {• Get rid of dialog box.}
  156.     SetPort(saveWPtr);                {• Restore the old port.}
  157. end.